package com.cll.mybatisPlus.model.dto;

import com.baomidou.mybatisplus.plugins.Page;
import lombok.Getter;
import lombok.ToString;

import java.io.Serializable;
import java.util.List;

/**
 * @author chenliangliang
 * @date 2018/1/27
 */
@Getter
@ToString
public class PageInfo<T> implements Serializable {

    private static final long serialVersionUID = -4523302018775765941L;


    /**
     * 每页条数
     */
    private int size;
    /**
     * 总条数
     */
    private long total;
    /**
     * 总页数
     */
    private int pages;
    /**
     * 当前页数
     */
    private int page;
    /**
     * 具体数据
     */
    private List<T> list;
    /**
     * 上一页
     */
    private int prePage;
    /**
     * 下一页
     */
    private int nextPage;
    /**
     * 是否是第一页
     */
    private boolean isFirstPage;
    /**
     * 是否是最后一页
     */
    private boolean isLastPage;
    /**
     * 是否有上一页
     */
    private boolean hasPrePage;
    /**
     * 是否有下一页
     */
    private boolean hasNextPage;


    public PageInfo(Page<T> page) {
        this.size = page.getSize();
        this.total = page.getTotal();
        this.pages = page.getPages();
        this.page = page.getCurrent();
        this.list = page.getRecords();

        this.prePage = this.page - 1 > 0 ? (this.page - 1) : 1;
        this.nextPage = this.page + 1 < this.pages ? (this.page + 1) : this.pages;

        isFirstPage = this.page == 1;
        isLastPage = this.page == this.pages;

        hasPrePage = this.page != this.prePage;
        hasNextPage = this.page != this.nextPage;
    }



}
